/**    
 * @{#} LoadingView.java Create on 2014-6-27 下午3:17:59    
 *          
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.my.commonlib.widget;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.my.commonlib.R;
import com.my.commonlib.util.CommonUIUtil;


public class LoadingView extends View {

	private static View view;

	static LoadingView loading;

	private static Activity lastActivity;
	private static ViewGroup mViewGroup;

	/**
	 * @param context
	 */
	public LoadingView(Context context) {
		super(context);
		view = LayoutInflater.from(context)
				.inflate(R.layout.view_loading, null);
	}

	public static void show(Context context) {
		Activity activity = (Activity) context;
		if (loading == null) {
			loading = new LoadingView(activity);
		}
		if (lastActivity == null) {
			hide(activity);
		} else {
			hide(lastActivity);
		}
		CommonUIUtil.addView(activity, view, 0, false, false);
		lastActivity = activity;
	}

	public static void show(Context context, ViewGroup group) {
		Activity activity = (Activity) context;
		if (loading == null) {
			loading = new LoadingView(activity);
		}
		if (mViewGroup == null) {
			hide(group);
		} else {
			hide(mViewGroup);
		}
		CommonUIUtil.addView(group, view, 0, false, false);
		mViewGroup = group;
	}

	public static void hide(Context context) {
		if (view != null) {
			CommonUIUtil.removeView(context, view);
		}
	}

	public static void hide(ViewGroup group) {
		if (view != null) {
			CommonUIUtil.removeView(group, view);
		}
	}
}
